<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ page import="com.esaheki.flashcards.dao.*"%>
<%@ page import="com.esaheki.flashcards.classes.*"%>
<%@ page import="com.esaheki.flashcards.support.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.NumberFormat"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!-- Header -->
<c:import url="/includes/header.jsp">
<c:param name="title" value="FlashCards" />
</c:import>
<!-- Header -->

<div class="colmask leftmenu"> 
<div class="colright"> 
<div class="col2"> 
<!-- Column Left --> 
            
<c:import url="/tree.jsp" />

<!-- Column Left --> 
</div>

<div class="col1wrap"> 
<div class="col1"> 

<!-- Column Right --> 
<%
String type = request.getParameter("type");
String id = request.getParameter("id");
String cid = request.getParameter("cid");
String answer = request.getParameter("answer");

CardDAO cardDao = new CardDAO();
CategoryDAO catDao = new CategoryDAO();
UserDAO userDao = new UserDAO();

Card card = new Card();
String front = "";
String back = "_";

if (answer.equals("yes")) {
	card = cardDao.getCardById(Integer.parseInt(cid));
	front = card.getFront();
	back = card.getBack();
}
else {
	if (type.equals("user")) {
		User user = userDao.getUserById(Integer.parseInt(id));
		card = new Roulette(user).getCard();
	}
	else if (type.equals("cat")) {
		Category cat = catDao.getCategoryById(Integer.parseInt(id));
		card = new Roulette(cat).getCard();
	}
	cid = String.valueOf(card.getId());
	front = card.getFront();
	back = "_";
}

%>
<div class="test">
<h2><%=front %></h2>
<h2><%=back %></h2>
</div>
<div class="answermenu">
<%
if (answer.equals("yes")) {
%>
<a class="greenlink" href="score?type=<%=type %>&id=<%=id %>&cid=<%=cid %>&inc=1">Right</a> | 
<a class="redlink" href="score?type=<%=type %>&id=<%=id %>&cid=<%=cid %>&inc=0">Wrong</a>
<%
} else { %>
<a href="test.jsp?type=<%=type %>&id=<%=id %>&answer=yes&cid=<%=cid %>">Show Answer</a>
<%
}
%>
</div>
<!-- Column Right --> 
</div> 
</div> 
</div> 
</div> 

<!-- Footer -->
<c:import url="/includes/footer.jsp" />
<!-- Footer -->